// pages/tabBar/specialty/specialty.js
const app = getApp();
import {
    _post,
    getLocation
} from '../../../utils/httpUtils.js'
Page({
    data: {
        showLoc: app.globalData.city,
        grid3: [],
        grid2: [],
        goodsHot: [],
        headnav: [{
                "imgpath": 'city_nav1.png',
                "text": '网红打卡',
                "ac_mark": 'clock'
            },
            {
                "imgpath": 'city_nav2.png',
                "text": '典故传说',
                "ac_mark": 'allusions'
            },
            {
                "imgpath": 'city_nav3.png',
                "text": '光阴故事',
                "ac_mark": 'story'
            },
            {
                "imgpath": 'city_nav4.png',
                "text": '风俗传统',
                "ac_mark": 'tradition'
            },
        ],
        winHeight: "", //窗口高度
        scrollY: '',
        navTransparency: 0, //导航栏透明度
        height: app.globalData.height,
        navHei: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.navWrapHeight();
        this.getCityRhyme(this.data.showLoc)
    },
    // 滚动监听
    onPageScroll(event) {
        let pageScrollTop = event.scrollTop;
        // 滑动导航栏效果
        if (pageScrollTop > 0 && pageScrollTop <= this.data.navHei) {
            this.setData({
                navTransparency: pageScrollTop / this.data.navHei
            })
        } else if (pageScrollTop > this.data.navHei) {
            this.setData({
                navTransparency: 1
            })
        } else if (pageScrollTop <= 0) {
            this.setData({
                navTransparency: 0
            })
        }
    },
    // 获取导航栏的高度
    navWrapHeight() {
        let query = wx.createSelectorQuery()
        query.select('.nav-wrap').boundingClientRect((res) => {
            this.data.navHei = res.height
        }).exec();
    },
    getCityRhyme(cityname) { //获取城韵数据
        _post('/api/CityRhyme/index', {
            'city_name': cityname
        }, res => {
            wx.stopPullDownRefresh()
            if (res.data.code == 1) {
                let data = res.data.data
                let grid2 = [],
                    grid3 = [];
                grid2.push(data.attractions, data.raiders)
                grid3.push(data.flavour, data.scenic, data.craft)
                this.setData({
                    banner: data.carousel, //banner
                    attractions: grid2, //动态赋值 // 名胜古迹,游玩攻略 重新赋值
                    characteristic: grid3, //动态赋值 // 当地味道 特色景区 匠心工艺
                    special: data.special
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: none,
                    duration: 2000
                })
                return
            }
        })
    },
    getList(e) { //获取分类列表
        let ac_mark = e.currentTarget.dataset.ac_mark;
        let data = {
            city_name: this.data.showLoc,
            ac_mark: ac_mark,
            page: 1
        }
        wx.navigateTo({
            url: `/pages/public/article_list/article_list?queryData=${JSON.stringify(data)}`,
        })

    },
    detail(e) { //进入详情 
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/public/article_detail/article_detail?id=${id}`,
        })
    },
    plantingDetail(e) { // 轮播图跳转文章详情
        let dataset = e.currentTarget.dataset;
        if (dataset.type == 1) {
            wx.navigateTo({
                url: `/pages/public/article_detail/article_detail?id=${dataset.id}`,
            })
        }
    },
    search() {
        wx.navigateTo({
            url: `/pages/tabBar/index/search/se`,
        })
    },
    onPullDownRefresh() {
        // this.getCityRhyme(this.data.showLoc)
        this.onLoad()
    }
})